class Solution {
public:
    int finalPositionOfSnake(int n, vector<string>& commands) {
        // vector<vector<int>> g(n, vector<int>(n, 0));
        // for(int i = 0; i < n; i++)
        //     for(int j = 0; j < n; j++)
        //         g[i][j] = (i * n) + j;
        int x = 0, y = 0;
        for(string &s : commands)
        {
            if(s == "UP") x -= 1;
            else if(s == "RIGHT") y += 1;
            else if(s == "DOWN") x += 1;
            else y -= 1;
        }
        // return g[x][y];
        return x * n + y;
    }
};
